package com.virgo.common.entity;

import com.virgo.common.utils.ITimeUtils;
import lombok.Data;

@Data
public class IResponse<T> {

	private String error;

	private Integer errorCode;

	private T data;

	private String time;

	public static<T> IResponse<T> ok(){
		IResponse<T> result = new IResponse<T>();
		result.setError("");
		result.setErrorCode(0);
		result.setData(null);
		result.setTime(ITimeUtils.localDate());
		return result;
	}

	public static<T> IResponse<T> ok(T data){
		IResponse<T> result = new IResponse<T>();
		result.setError("");
		result.setErrorCode(0);
		result.setData(data);
		result.setTime(ITimeUtils.localDate());
		return result;
	}

	public static<String> IResponse<String> logout(){
		IResponse<String> result = new IResponse<>();
		result.setError("请登录");
		result.setErrorCode(2000);
		result.setData(null);
		result.setTime(ITimeUtils.localDate());
		return result;
	}

	public static<T> IResponse<T> fail(String error){
		IResponse<T> result = new IResponse<T>();
		result.setError(error);
		result.setErrorCode(2001);
		result.setData(null);
		result.setTime(ITimeUtils.localDate());
		return result;
	}

	public static<T> IResponse<T> fail(String error, Integer errorCode){
		IResponse<T> result = new IResponse<T>();
		result.setError(error);
		result.setErrorCode(errorCode);
		result.setData(null);
		result.setTime(ITimeUtils.localDate());
		return result;
	}
}